package cn.uniquetech.hky;

public class GenControllerUtil {
	public static String parseControllerClass(String tableName, String tableRemarks) {
		String servicePackage = GenerateCodeMysql.PACKAGENAME + ".controller";
		String clazz = tableName;
		String lowClazz = clazz.toLowerCase();
		StringBuffer sb = new StringBuffer();

		sb.append("package " + servicePackage + ";\r\n\r\n");
		sb.append("import org.springframework.beans.factory.annotation.Autowired;\r\n");
		sb.append("import org.springframework.stereotype.Controller;\r\n");
		sb.append("import org.springframework.web.bind.annotation.RequestMapping;\r\n");
		sb.append("import " + GenerateCodeMysql.PACKAGENAME + ".controller.base.BaseController;\r\n");
		sb.append("import " + GenerateCodeMysql.PACKAGENAME + ".vo." + clazz + "VO" + ";\r\n");
		sb.append("import " + GenerateCodeMysql.PACKAGENAME + ".service.I" + clazz + "Service;\r\n");
		sb.append("\r\n");

		sb.append("/**" + "\r\n");
		sb.append("* @创建人名 " + GenerateCodeMysql.cjrName + "\r\n");
		sb.append("* @创建日期 " + DateUtil.curDateTime() + "\r\n");
		sb.append("* @文件描述 " + tableRemarks + "控制器\r\n");
		sb.append(" */" + "\r\n");

		sb.append("\r\n");
		sb.append("@Controller");
		sb.append("\r\n");
		sb.append("@SuppressWarnings(\"unused\")");
		sb.append("\r\n");
		sb.append("@RequestMapping(value = \"/" + lowClazz + "\")");
		sb.append("\r\n");
		sb.append("public class " + clazz + "Controller extends BaseController<" + clazz + "VO" + ">" + "{\r\n\r\n");
		sb.append("private I" + clazz + "Service " + lowClazz + "Service;" + "\r\n");
		sb.append("@Autowired\r\n");
		sb.append("public " + clazz + "Controller(I" + clazz + "Service " + lowClazz + "Service) {\r\n");
		sb.append("\t\tsuper();\r\n");
		sb.append("\t\t" + "this.baseService = " + lowClazz + "Service;" + "\r\n");
		sb.append("\t\t" + "this." + lowClazz + "Service = " + lowClazz + "Service;" + "\r\n");

		sb.append("\t\t" + "this.viewPath=\"/mgr/" + lowClazz + "\";\r\n");
		sb.append("\t\t" + "this.viewName=\"" + tableRemarks + "\";\r\n");

		sb.append("\t}\r\n");
		sb.append("}\r\n");
		FileUtil.writeFile(servicePackage, clazz + "Controller.java", sb.toString());
		return sb.toString();
	}
}
